﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace CoreShop.App
{
    [StructLayout(LayoutKind.Sequential)]
    public struct SM_EANData
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst=10)]
        public byte[] ItemCode;     //项目代码  十位
        [MarshalAs(UnmanagedType.I4)]
        public Int32 BarCodeType;   //条码类型 0-EAN ;9-ITF
        [MarshalAs(UnmanagedType.I4)]
        public Int32 BarRightData;  //右侧数据

        public void Initializa()
        {
            ItemCode = new byte[10];
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct SMDiscount
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 StartDate;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 StartTime;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 EndDate;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 EndTime;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 FirstLIM;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Within1stLIM;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 SecondLIM;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Within2ndLIM;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 DisType;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 MarkDown;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct SM_ASCII_TXT
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TwsFontSize;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
        public byte[] TxtValue;

        public void Initialize()
        {
            TxtValue = new byte[100];
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct MutilBarcode
    {
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 MutilBarFunc;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst=49)] 
        public byte[] MutilBarData;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 MutilBarType;

        public void Initialize()
        {
            MutilBarData = new byte[49];
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct PluFIle
    {
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 PLUNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 WeightUnit;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 UPriceOverride;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 UPrice;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 LabelFormat1;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 LabelFormat2;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 BarFormat;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 EANFlags;
        [MarshalAs(UnmanagedType.Struct)]
        public SM_EANData EAN_Data;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 MG;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 SBDate;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 UBDate;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 Cost;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 Tare;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 QTY;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 TaxNo;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 Traceability;
        [MarshalAs(UnmanagedType.I4)] 
        public Int32 TraceabilityL;

        [MarshalAs(UnmanagedType.Struct)]
        public MutilBarcode MBarcode1;
        [MarshalAs(UnmanagedType.Struct)] 
        public SMDiscount Discount;

        [MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
        public SM_ASCII_TXT[] Commodity;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst=15)] 
        public SM_ASCII_TXT[] Ingredient;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst=30)] 
        public SM_ASCII_TXT[] SPMessage;

        public void Initialize()
        {
            int i;
            EAN_Data = new SM_EANData();
            EAN_Data.Initializa();
            MBarcode1 = new MutilBarcode();
            MBarcode1.Initialize();
            Discount = new SMDiscount();

            Commodity = new SM_ASCII_TXT[4];
            for (i = 0; i < Commodity.Length; i++)
            {
                Commodity[i] = new SM_ASCII_TXT();
                Commodity[i].Initialize();
            }

            Ingredient = new SM_ASCII_TXT[15];
            for (i = 0; i < Ingredient.Length; i++)
            {
                Ingredient[i] = new SM_ASCII_TXT();
                Ingredient[i].Initialize();
            }

            SPMessage = new SM_ASCII_TXT[30];
            for (i = 0; i < SPMessage.Length; i++)
            {
                SPMessage[i] = new SM_ASCII_TXT();
                SPMessage[i].Initialize();
            }
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct MGFile
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecordNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecSize;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 LnDeptNo;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
        public byte[] Name;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TaxRateNo;

        public void Initialize()
        {
            Name = new byte[16];
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct DeptFile
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecordNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecSize;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
        public byte[] Name;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 CodeType;

        public void Initialize()
        {
            Name = new byte[16];
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct PLUTotalTranFile
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecordNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PLUNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 UPrice;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Weight;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 QTY;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TPrice;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Date;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Time;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)]
        public byte[] TraceCode;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ScaleNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 BPrice;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 APrice;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)]
        public byte[] ItemCode;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
        public byte[] ItemName;

        public void Initialize()
        {
            TraceCode = new byte[9];
            ItemCode  = new byte[14];
            ItemName  = new byte[50];
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct ReceiptDetail
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecordNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecordSize;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ItemStatus;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PluNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 MG;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 QTY;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Weight;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Uprice;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 UpriceAfDisc;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 UPDiscAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 NPrice;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ActPrice;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PriceAfDiscTax;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PriceAfSTTLDisc;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PriceAfUPOV;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TTLPriceDiscAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ItPriceAFTTLRD;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TaxRtNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Dummy1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TaxRt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TaxVal;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TaxValAfSTTLDisc;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SPPriceNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Dummy2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ScaleNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Dummy3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ValOfPoint1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PriceOfPoint1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ValOfPoint2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PriceOfPoint2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TareVal;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 StPointDiscStat;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 MarkdStat;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SaleDate;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SaleTime;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PublicFreeWT;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PublicBonus;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PublicFreeQTY;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 BornCountry;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 FatCountry;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SlaugHouse;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SlaugCountry;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 CutHall;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 CutCountry;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ReferDate;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 OriginCountry;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
        public byte[] ReferCode;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ReferType;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ReferSet;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayTTLNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Dummy4;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmt1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAMtEuro1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmt2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAMtEuro2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmt3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAMtEuro3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve3;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)]
        public byte[] Gtin;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Kind;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Category;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Breed;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
        public byte[] LotNo;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
        public byte[] ContactRef;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 EatDate;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TraceWT;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TraceID;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PriceBfDisc;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)]
        public byte[] ItemCode;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 IPAddrTail;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
        public byte[] ItemName;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SellDate;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)]
        public byte[] PluEan;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ScalePtNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Dummy5;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ClerkNo;

        public void Initialize()
        {
            ReferCode = new byte[20];
            Gtin = new byte[14];
            LotNo = new byte[30];
            ContactRef = new byte[10];
            ItemCode = new byte[14];
            ItemName = new byte[50];
            PluEan = new byte[14];
        }
    }


    [StructLayout(LayoutKind.Sequential)]
    public struct ReceiptTotal
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecordNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecordSize;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 NTrans;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 BufStat;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RCTNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ActTrans;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RefundTrans;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 NewPLUTrans;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
        public byte[] ClerkName;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AdSubStat;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Dummy1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Weight;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 QTY;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SubGAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 NPrice;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SubNetAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TSubNetAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PriceWTax;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TPriceWTax;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtOfATax;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtOfVTax;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TAmtOfATax;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TAmtOfVTax;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SubDiscAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SubDiscP;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SubItDiscAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SubItDiscRem;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtOfRebate;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 CashRecv;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 NoOfCashPay;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ValOfCheques;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 NoOfCheques;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ValOfVoucher;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 NoOfVoucher;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 FCustomerNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 FCustomerTbl;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ValOfCredit;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 NoOfCredit;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Dummy2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SaleDate;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Dummy3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 SaleTime;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ScalePtNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ClerkNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RTRCTNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ScaleNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TenderAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ChangeAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 DiscAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 NetAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 CustomerNo;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
        public byte[] Barcode;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 EFTChange;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 EFTChangeNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Bonus;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtWGST;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtWOGST;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RoundingAmt;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Dummy4;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo4;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY4;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL4;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE4;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve4;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo5;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY5;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL5;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE5;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve5;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo6;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY6;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL6;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE6;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve6;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo7;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY7;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL7;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE7;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve7;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo8;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY8;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL8;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE8;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve8;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo9;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY9;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL9;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE9;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve9;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo10;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY10;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL10;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE10;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve10;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo11;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY11;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL11;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE11;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve11;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo12;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY12;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL12;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE12;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve12;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo13;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY13;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL13;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE13;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve13;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo14;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY14;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL14;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE14;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve14;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo15;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY15;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL15;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE15;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve15;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayNo16;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayQTY16;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtL16;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PayAmtE16;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Reserve16;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RCTTaxAmt1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RCTTaxAmt2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RCTTaxAmt3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RCTTaxAmt4;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RCTTaxAmt5;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RCTTaxAmt6;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RCTTaxAmt7;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RCTTaxAmt8;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RCTTaxAmt9;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RCTTaxAmt10;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtETax1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtETax2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtETax3;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtETax4;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtETax5;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtETax6;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtETax7;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtETax8;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtETax9;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 AmtETax10;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 CreditRecNo;

        public void Initialize()
        {
            ClerkName = new byte[17];
            Barcode = new byte[16];
        }

    }

    [StructLayout(LayoutKind.Sequential)]
    public struct StockOperation
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecordNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecordSize;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Time;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Date;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Dummy1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ScaleNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PluNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 WeightOrQTY;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ListNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ItemType;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 StockType;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Status;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RtReason;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 26)]
        public byte[] InboundNo;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 74)]
        public byte[] Reserved;

        public void Initialize()
        {
            InboundNo = new byte[26];
            Reserved = new byte[74];
        }

    }

    [StructLayout(LayoutKind.Sequential)]
    public struct FlexiBarcode
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecordNo;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 RecSize;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 FlagType;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ItemDigit;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PData1Digit;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PData2Digit;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 MidChkDigit;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 LastChkDigit;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 BarcodeType;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PData1;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PData2;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PData1Shift;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 PData2Shift;
    };

    [StructLayout(LayoutKind.Sequential)]
    public struct PresetKey
    {
        [MarshalAs(UnmanagedType.I4)]
    	public Int32 RecordNo;
        [MarshalAs(UnmanagedType.I4)]
    	public Int32 RecSize;
        [MarshalAs(UnmanagedType.I4)]
    	public Int32 PageNo;
        [MarshalAs(UnmanagedType.I4)]
    	public Int32 KeyNo;
        [MarshalAs(UnmanagedType.I4)]
    	public Int32 KeySwitchNo;
        [MarshalAs(UnmanagedType.I4)]
    	public Int32 Status;
        [MarshalAs(UnmanagedType.I4)]
    	public Int32 CSize;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst=24)]
        public byte[] PSKName;
        [MarshalAs(UnmanagedType.I4)]
    	public Int32 ReferFile;

        public void Initialize()
        {
            PSKName = new byte[24];
        }
    };


    [StructLayout(LayoutKind.Sequential)]
    public struct SM_EANData_Test
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
        public byte[] ItemCode;     //项目代码  十位
        [MarshalAs(UnmanagedType.I4)]
        public Int32 BarCodeType;   //条码类型 0-EAN ;9-ITF
        [MarshalAs(UnmanagedType.I4)]
        public Int32 BarRightData;  //右侧数据

        public void Initialize()
        {
            ItemCode = new byte[10];
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct ScaleDataFile
    {
        [MarshalAs(UnmanagedType.I4)]
    	public int RecordNo;
        [MarshalAs(UnmanagedType.I4)]
	    public int RecSize;
        [MarshalAs(UnmanagedType.I4)]
	    public int Dept;
        [MarshalAs(UnmanagedType.I4)]
	    public int Rct_Shop;
        [MarshalAs(UnmanagedType.I4)]
    	public int Lbl_Shop;
        [MarshalAs(UnmanagedType.I4)]
    	public int Preset_Key;
        [MarshalAs(UnmanagedType.I4)]
    	public int Scale_Code;
        [MarshalAs(UnmanagedType.I4)]
    	public int I_Lbl_Format;
        [MarshalAs(UnmanagedType.I4)]
    	public int T_Lbl_Format;
        [MarshalAs(UnmanagedType.I4)]
	    public int I_Bar_Barcode;
        [MarshalAs(UnmanagedType.I4)]
    	public int I_Bar_R_Data;
        [MarshalAs(UnmanagedType.I4)]
    	public int I_Bar_R_Price_Data;
        [MarshalAs(UnmanagedType.I4)]
    	public int I_Bar_Flag;
        [MarshalAs(UnmanagedType.I4)]
    	public int T_Barcode;
        [MarshalAs(UnmanagedType.I4)]
    	public int T_Bar_L_Data;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
    	public byte[] T_Bar_Fix_L_Data;
        [MarshalAs(UnmanagedType.I4)]
    	public int T_Bar_Flag;
        [MarshalAs(UnmanagedType.I4)]
    	public int T_Bar_R_Data;
        [MarshalAs(UnmanagedType.I4)]
	    public int T_Bar_Prt_Rct;
        [MarshalAs(UnmanagedType.I4)]
    	public int Prt_Bar_F1;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
    	public byte[] Last_Act_Date;
        [MarshalAs(UnmanagedType.I4)]
    	public int Plu_Call_Low;
        [MarshalAs(UnmanagedType.I4)]
    	public int Plu_Call_Upper;
        [MarshalAs(UnmanagedType.I4)]
    	public int Apc_Date;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
	    public byte[] Ethernet_Addr;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
    	public byte[] Ip_Addr;
        [MarshalAs(UnmanagedType.I4)]
	    public int Thermal_Hd_Usage_Ctr;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
	    public byte[] Version_Num_Main;
        [MarshalAs(UnmanagedType.I4)]
	    public int Number_Plu;
        [MarshalAs(UnmanagedType.I4)]
	    public int Ram_Size;
        [MarshalAs(UnmanagedType.I4)]
	    public int Preset_Group;
        [MarshalAs(UnmanagedType.I4)]
	    public int Rct_Sp;
        [MarshalAs(UnmanagedType.I4)]
	    public int Program_Update_Chk;
        [MarshalAs(UnmanagedType.I4)]
	    public int Mainboard_Type;
        [MarshalAs(UnmanagedType.I4)]
	    public int Plu_Remain;
        [MarshalAs(UnmanagedType.I4)]
	    public int Data_Update_Date;
        [MarshalAs(UnmanagedType.I4)]
	    public int Data_Update_Time;

        public void Initialize()
        {
            T_Bar_Fix_L_Data = new byte[10];
            Last_Act_Date = new byte[16];
            Ethernet_Addr = new byte[12];
            Ip_Addr = new byte[12];
            Version_Num_Main = new byte[4];

        }
    };





#if FALSE


    [StructLayout(LayoutKind.Sequential)]
    public struct SM_ASCII_TXT_TEST
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
        public string TxtValue;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 TwsFontSize;
    }

    public struct PluFIleTest
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
        public string ss;
        [MarshalAs(UnmanagedType.I1)]
        public char cc;
//         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
//         public SM_ASCII_TXT_TEST[] Commodity;
//         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
//         public SM_ASCII_TXT_TEST[] SPMessage;
        
        [MarshalAs(UnmanagedType.I1)]
        public char PLUNo;


        public void Initialize()
        {
            int i;

//             Commodity = new SM_ASCII_TXT_TEST[2];
//             for (i = 0; i < Commodity.Length; i++)
//                 Commodity[i] = new SM_ASCII_TXT_TEST();
// 
//             SPMessage = new SM_ASCII_TXT_TEST[10];
//             for (i = 0; i < SPMessage.Length; i++)
//                 SPMessage[i] = new SM_ASCII_TXT_TEST();
        }
    }


    [StructLayout(LayoutKind.Sequential)]
    public struct sub_strup
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 m;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)]
        public String data;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 n;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct stru_p
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 i;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
        public String ss;
        [MarshalAs(UnmanagedType.Struct)]
        public SM_EANData eandata;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
        public sub_strup[] subp;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
        public sub_strup[] subp2;

        [MarshalAs(UnmanagedType.I4)]
        public Int32 j;

        public void Initialize()
        {
            subp = new sub_strup[10];
            for (int i = 0; i < subp.Length;i++ )
            {
                subp[i] = new sub_strup();
            }
            subp2 = new sub_strup[10];
            for (int i = 0; i < subp2.Length; i++)
            {
                subp2[i] = new sub_strup();
            }
        }
    }
#endif

    public class DllCall
    {

/*
        [DllImport("dlltest.dll", 
         CallingConvention=CallingConvention.StdCall,
         EntryPoint="fnDlltest")]
         public static extern Int32 fnDlltest(Int32 socks, ref SM_EANData_Test sp);
*/


        [DllImport("SMScaleAPI.dll", 
         CallingConvention=CallingConvention.StdCall, 
         EntryPoint="ConnectScale" )]
         public static extern Int32 Connect(String IPAddr, Int32 Port);

        [DllImport("SMScaleAPI.dll", 
         CallingConvention=CallingConvention.StdCall, 
         EntryPoint="CloseConnect")]
         public static extern Int32 Disconnect(Int32 sock);

        [DllImport("SMScaleAPI.dll", 
         CallingConvention=CallingConvention.StdCall,
         EntryPoint="DelPluFile")]
         public static extern Int32 DelAllPlus(Int32 sock);

        [DllImport("SMScaleAPI.dll", 
         CallingConvention=CallingConvention.StdCall,
         EntryPoint="SendLPlu")]
         public static extern Int32 SendLabelPLU( Int32 sock, ref PluFIle PLUData);

        [DllImport("SMScaleAPI.dll", 
         CallingConvention=CallingConvention.StdCall, 
         EntryPoint="SendMainGroup")]
         public static extern Int32 SendMainGroup( Int32 sock, ref MGFile MGData);

        [DllImport("SMScaleAPI.dll", 
         CallingConvention=CallingConvention.StdCall,
         EntryPoint="DelMGFile")]
         public static extern Int32 DelAllMGs(Int32 sock);

        [DllImport("SMScaleAPI.dll", 
         CallingConvention=CallingConvention.StdCall,
         EntryPoint="SendDepartment")]
         public static extern Int32 SendDepartment(Int32 sock, ref DeptFile DeptData);

        [DllImport("SMScaleAPI.dll", 
         CallingConvention=CallingConvention.StdCall,
         EntryPoint="DelDeptFile")]
         public static extern Int32 DelAllDepts(Int32 sock);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "ReadPLUTTLTrans")]
         public static extern Int32 ReadPLUTTLTrans(Int32 sock, Int32 RecordNo, ref PLUTotalTranFile plutransitem);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "DelPLUTTLTrans")]
         public static extern Int32 DelPLUTTLTrans(Int32 sock, Int32 RecordNo);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "ReadReceiptTotal")]
         public static extern Int32 ReadReceiptTotal(Int32 sock, Int32 RecordNo, ref ReceiptTotal plutransitem);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "ReadReceiptDetail")]
         public static extern Int32 ReadReceiptDetail(Int32 sock, Int32 RecordNo, ref ReceiptDetail plutransitem);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "DelReceiptDetailRD")]
         public static extern Int32 DelReceiptDetailRD(Int32 sock, Int32 RecordNo);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "DelReceiptTotalRD")]
         public static extern Int32 DelReceiptTotalRD(Int32 sock, Int32 RecordNo);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "ReadStock")]
         public static extern Int32 ReadStock(Int32 sock, Int32 RecordNo, ref StockOperation stockdata);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "DelStockRD")]
         public static extern Int32 DelStockRD(Int32 sock, Int32 RecordNo);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "SyncDateTime")]
         public static extern Int32 SyncDateTime(Int32 sock);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "SendFlexiBarcode")]
         public static extern Int32 SendFlexiBarcode(Int32 sock, ref FlexiBarcode barcodedata);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "SendPresetKey")]
         public static extern Int32 SendPresetKey(Int32 sock, ref PresetKey pskdata);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "DelPSKFile")]
         public static extern Int32 DelPSKFile(Int32 sock);

        [DllImport("SMScaleAPI.dll",
         CallingConvention = CallingConvention.StdCall,
         EntryPoint = "ReadScaleData")]
        public static extern Int32 ReadScaleData(Int32 sock, Int32 RecordNo, ref ScaleDataFile scaleDatafile);


    }
}
